<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/7/1
  Time: 9:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$</title>
    <link rel="stylesheet" href="css/css.css">
    <link rel="stylesheet" href="css/img.css">
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <script>
        $(function () {
            $.ajax({
                url:"brand.do",
                type:"post",
                dataType:"json",
                success:function (obj) {
                    for (let x in obj) {
                        $("[name='bid']").append("<option value="+obj[x].bid+">"+obj[x].bname+"</option>");
                    }
                }
            })
        })
        function fenye(pages) {
            $("[name='pages']").val(pages);
            $("form").submit();
        }
        function qx() {
            $("[name='sid']").prop("checked",true);
        }
        function qbx() {
            $("[name='sid']").prop("checked",false);
        }
        function del(sid) {
            if(confirm("您确定要删除吗?")){
                $.ajax({
                    url:"del.do",
                    data:{"sid":sid},
                    type:"post",
                    dataType:"json",
                    success:function (obj) {
                        if (obj>0){
                            alert("删除成功");
                            location.href="list.do";
                        }else {
                            alert("删除失败");
                        }
                    }
                })
            }
        }
        function dels() {
            var str="";
            $("[name='sid']:checked").each(function () {
                str+=","+$(this).val();
            })
            var sid=str.substring(1);
            alert(sid);
            if(confirm("您确定要删除吗?")){
                $.ajax({
                    url:"dels.do",
                    data:{"sid":sid},
                    type:"post",
                    dataType:"json",
                    success:function (obj) {
                        if (obj>0){
                            alert("删除成功");
                            location.href="list.do";
                        }else {
                            alert("删除失败");
                        }
                    }
                })
            }
        }
    </script>
</head>
<body>
<form action="/list.do" method="post">
    <input type="hidden" name="pages">
    <input type="text" name="sname" placeholder="名称" value="${map.sname}">
    <input type="text" name="title" placeholder="标题" value="${map.title}">
    &emsp;品牌<select name="bid">
        <option value="">请选择</option>
    </select>
    &emsp;排序数据项<select name="xx">
        <option value="">请选择</option>
        <option value="sid" ${map.xx=='sid'?'selected':''} >id</option>
        <option value="sname" ${map.xx=='sname'?'selected':''} >名称</option>
        <option value="title" ${map.xx=='title'?'selected':''} >标题</option>
        <option value="bid" ${map.xx=='bid'?'selected':''} >品牌</option>
        <option value="atype" ${map.xx=='atype'?'selected':''} >分类</option>
        <option value="status" ${map.xx=='status'?'selected':''} >是否上架</option>
    </select>
    &emsp;排序方式<select name="px">
        <option value="">请选择</option>
        <option value="asc" ${map.px=='asc'?'selected':''} >升序</option>
        <option value="desc" ${map.px=='desc'?'selected':''} >降序</option>
    </select>
    <input type="submit" value="查询">
</form>
<input type="button" value="批量删除" onclick="dels()">
<a href="/toadd.do"><input type="button" value="添加"></a>
<table>
    <tr>
        <td>
            id
            <input type="button" value="全选" onclick="qx()">
            <input type="button" value="全不选" onclick="qbx()">
        </td>
        <td>名称</td>
        <td>图片</td>
        <td>品牌</td>
        <td>分类1</td>
        <td>分类2</td>
        <td>分类3</td>
        <td>上架</td>
        <td>标题</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${pageInfo.list}" var="s">
        <tr>
            <td>
                <input type="checkbox" name="sid" value="${s.sid}">    ${s.sid}
            </td>
            <td>${s.sname}</td>
            <td>
                 <img src="${s.pic}" alt="无法展示" width="100px">
            </td>
            <td>${s.bnames}</td>
            <td>${s.aname}</td>
            <td>${s.bname}</td>
            <td>${s.cname}</td>
            <td>${s.status}</td>
            <td>${s.title}</td>
            <td>
                <a href="/toupd.do?sid=${s.sid}"><input type="button" value="修改"></a>
                <input type="button" value="删除" onclick="del(${s.sid})">
                <a href="/toadd.do"><input type="button" value="添加Sku"></a>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="20">
            <input type="button" class="btn btn-info" value="首页" onclick="fenye(1)">
            <input type="button" class="btn btn-info" value="上一页" onclick="fenye(${pageInfo.isFirstPage?1:pageInfo.prePage})">
            <c:forEach items="${pageInfo.navigatepageNums}" var="index">
                <input type="button" class="btn btn-info" value="${index}" onclick="fenye(${index})">
            </c:forEach>
            <input type="button" class="btn btn-info" value="下一页" onclick="fenye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">
            <input type="button" class="btn btn-info" value="尾页" onclick="fenye(${pageInfo.pages})">
        </td>
    </tr>
</table>
</body>
</html>
